problem fetching currval of sequence - Mailing list pgsql-sql

From Charles Hauser
Subject problem fetching currval of sequence
Date
Msg-id a05111b00b97594e67c38@[152.3.11.193]
Whole thread Raw
Responses Re: problem fetching currval of sequence  ("Josh Berkus" <josh@agliodbs.com>)
Re: problem fetching currval of sequence  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-sql
Hi,

I have a script to load values into a table (gb) which contains a SEQUENCE ('gb_id').  For each entry into TABLE gb I need the value of 'gb_gb_id_seq' to update a relational table.   I am getting the following error msg:
                ERROR: gb_gb_id_seq.currval is not yet defined in this session.

If anyone knows why this is not working I would appreciate suggestions.



CREATE TABLE "gb" (
   "gb_id" int4 DEFAULT nextval('"gb_gb_id_seq"'::text) NOT NULL,
   "clone_id" int4,
   "accn" varchar(12) NOT NULL,
   "gi" int4 NOT NULL,
   CONSTRAINT "gb_pkey" PRIMARY KEY ("gb_id")
);

    foreach $id(sort keys %ACCN) {
      $conn->exec(
                   "UPDATE gb SET accn_no = '$ACCN{$id}{gb}',gi_no = '$ACCN{$id}{gi}' WHERE clone_id = '$ACCN{$id}{clone_id}'"
                   );

        $result = $conn->exec("SELECT currval('gb_gb_id_seq');");
        die $conn->errorMessage unless PGRES_TUPLES_OK eq $result->resultStatus;
        $gb_id = $result->fetchrow;
        $ACCN{$id}{gb_id} = $gb_id;
    }

-- 
Regards,

        Charles

pgsql-sql by date:

Previous
From: "Dan Langille"
Date:
Subject: Re: Transitive Closure
Next
From: Joerg Hessdoerfer
Date:
Subject: Re: Table design question...